package com.t3go.t3_map.base;

import androidx.annotation.NonNull;

import java.util.HashMap;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.platform.PlatformViewRegistry;

public class FlutterPlatformSingleFactory {
    private FlutterPlugin.FlutterPluginBinding mFlutterPluginBinding;

//    private static final FlutterPlatformSingleFactory sInstance = new FlutterPlatformSingleFactory();
//
//    public static FlutterPlatformSingleFactory getInstance() {
//        return sInstance;
//    }

    private final HashMap<String, CommonPlatformViewFactory> commonPlatformFactory = new HashMap<>();

    public FlutterPlatformSingleFactory(@NonNull FlutterPlugin.FlutterPluginBinding flutterPluginBinding) {
        mFlutterPluginBinding = flutterPluginBinding;
        BinaryMessenger binaryMessenger = mFlutterPluginBinding.getBinaryMessenger();
        commonPlatformFactory.put("com.t3.map.flutter.mapview", new CommonPlatformViewFactory(binaryMessenger));
    }

    public void registerFlutterFactory() {
        PlatformViewRegistry registry = mFlutterPluginBinding.getPlatformViewRegistry();
        registry.registerViewFactory("com.t3.map.flutter.mapview", getFactory("com.t3.map.flutter.mapview"));
    }

    public CommonPlatformViewFactory getFactory(String platformViewId) {
        return commonPlatformFactory.get(platformViewId);
    }
}
